package com.ruoyi.student.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.ruoyi.student.domain.StudentYfyd;
import com.ruoyi.student.domain.StudentYfydDto;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.BeanUtils;

/**
 * 学生一分一段excel录入信息
 * @author zhaoYuFei
 */
public class YfydListener  extends AnalysisEventListener<StudentYfydDto> {
    HashMap<String, String> excelMsg = new HashMap<>();
    List<StudentYfyd> list=new ArrayList<>();

    public YfydListener() {
    }

    public YfydListener(HashMap<String, String> excelMsg, List<StudentYfyd> list) {
        this.excelMsg = excelMsg;
        this.list = list;
    }

    @Override
    public void invoke(StudentYfydDto studentYfyd1, AnalysisContext analysisContext) {
        if (studentYfyd1.getScore().contains("分段表")){
            String types = studentYfyd1.getScore();
            String[] parts = types.split(" ");
            excelMsg.put("类型",parts[2]);
        }else {
            if (!"分数".equals(studentYfyd1.getScore())){
                studentYfyd1.setProvince(excelMsg.get("省份"));
                studentYfyd1.setYear(excelMsg.get("年份"));
                studentYfyd1.setType(excelMsg.get("类型"));
                StudentYfyd studentYfyd = new StudentYfyd();
                BeanUtils.copyProperties(studentYfyd1,studentYfyd);
                studentYfyd.setNumberOfPeople(Long.valueOf(studentYfyd1.getNumberOfPeople()) );
                list.add(studentYfyd);
            }}
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
            System.out.println( "解析完成" );
    }
}
